﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;

namespace BLLA
{
    public partial class View_Order_Dishes : BaseBLL<Model.View_Order_Dishes>, IBLL.IView_Order_DishesBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();

        /// <summary>
        /// 根据商户权限获取商品信息列表
        /// </summary>
        /// <param name="MerID">商户ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetOrder_Dishes(string MerID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                List<Model.View_Order_Dishes> ls = new List<Model.View_Order_Dishes>();
                ls = base.GetListBy("SELECT * FROM  View_Order_Dishes where MerID='"+MerID+"' and DishesTypeState=1");
                if (ls != null & ls.Count > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = ls;
                    result.total = ls.Count;
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("根据商户权限获取商品信息列表失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }


        /// <summary>
        /// 获取热门商品--by lz--统计不准确，改用get_count接口
        /// </summary>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns>List<Model.View_Order_Dishes></returns>
        public string Get_Dishes_sort(string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion

                #region 业务逻辑
                List<Model.View_Order_Dishes> ls = new List<Model.View_Order_Dishes>();
                ls = base.GetListBy("select  top 5 * from View_Order_Dishes  order by DishesVol desc ");//查询销量前三个商品
                if (ls != null & ls.Count > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = ls;
                    result.total = ls.Count;
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
                #endregion

            }
            catch (Exception ex)
            {
                WriteLog.WriteW("获取热门商品失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }
    }
}
